package org.op.looks;

import org.op.FrameView;
import org.op.editor.doc.DocumentReloadController;
import org.op.service.config.ConfigKeys;
import org.op.service.config.ConfigurationService;
import org.op.service.log.LoggerService;
import org.op.util.MessageController;

public class FontControllerImpl implements FontController {

	private SetFontPopupView popupView;
	private ConfigurationService configService;
	private DocumentReloadController reloadController;
	private FrameView frameView;
	private MessageController messageController;
	private LoggerService logger;

	public void configureFonts() {
		try {
			popupView.setFrame(frameView.getFrame());
			
			boolean submit = popupView.showAndGet();
			if (submit) {
				String fontFamily = popupView.getFontFamily();
				String fontSize = popupView.getFontSize();
				
				// set the configuration parameters
				if (fontFamily!=null && fontSize!=null) {
					configService.updateProperty(ConfigKeys.STYLE_FONT_FAMILY, fontFamily);
					configService.updateProperty(ConfigKeys.STYLE_FONT_SIZE, fontSize);
				}
				
				// refresh all open editors
				reloadController.reloadAllDocuments();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public SetFontPopupView getPopupView() {
		return popupView;
	}

	public void setPopupView(SetFontPopupView popupView) {
		this.popupView = popupView;
	}

	public ConfigurationService getConfigService() {
		return configService;
	}

	public void setConfigService(ConfigurationService configService) {
		this.configService = configService;
	}

	public DocumentReloadController getReloadController() {
		return reloadController;
	}

	public void setReloadController(DocumentReloadController reloadController) {
		this.reloadController = reloadController;
	}

	public FrameView getFrameView() {
		return frameView;
	}

	public void setFrameView(FrameView frameView) {
		this.frameView = frameView;
	}

	public MessageController getMessageController() {
		return messageController;
	}

	public void setMessageController(MessageController messageController) {
		this.messageController = messageController;
	}
	
	public LoggerService getLogger() {
		return logger;
	}

	public void setLogger(LoggerService logger) {
		this.logger = logger;
	}
}
